// Copyright 2009, Lucid Technics, LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in
// writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

importClass(Packages.java.io.File);
importClass(Packages.org.apache.commons.io.FileUtils);
importClass(Packages.org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory);
importClass(Packages.com.svnservices.util.Constants);

CONTENT_CONTEXT.type = "application/xhtml+xml";

var [repository, errorMap] = h.populate();

if (errorMap.isEmpty() === true)
{
	var repositoryRoot = SERVLET.getServletConfig().getInitParameter("rr.repository.root");
    var reposFile = new File(repositoryRoot, repository.name);

    FSRepositoryFactory.setup();

	try
	{
		FileUtils.deleteDirectory(reposFile);

		CONTENT_CONTEXT.content = h.msg200();
	}
	catch(e)
	{	
		LOG.error("Encountered exception:" + e + " while trying to get repository list.");
		CONTENT_CONTEXT.content = h.msg500();
	}
}
else
{
	CONTENT_CONTEXT.content = h.msg401(errorMap);
}